///////////////////////////////////////////////////////////////////////////////
//
// Licensed under the MIT License
//
// Copyright (c) 2010 Chris Colinsky
// All Rights Reserved
//
// version	0.5
// http://code.google.com/p/sugarcookie/
// http://code.google.com/p/sugarcookie/wiki/License
//
////////////////////////////////////////////////////////////////////////////////

package sugarcookie.framework {
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	import mx.logging.Log;
	
	import sugarcookie.commands.ICommand;
	import sugarcookie.display.SpriteBase;
	import sugarcookie.error.ApplicationError;
	import sugarcookie.framework.vo.NavData;

	/**
	 * Represents a view within the application that is managed by the ViewStack.
	 */
	public class View extends SpriteBase implements IView {
		protected var _dm:IModel;
		protected var _nd:NavData;
		protected var _command:ICommand;
		
		public function View() {
			super();
			_log = Log.getLogger("sugarcookie.framework.View");
			addEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
		}
		
		private function onAddedToStage(evt:Event):void {
			removeEventListener(Event.ADDED_TO_STAGE,onAddedToStage);
			onAdded();
		}
		
		public function set dataManager(dm:IModel):void {
			_dm = dm;
		}
		
		public function show(data:*=null):void {
			//do custom set up in subclass
			throw new ApplicationError("View.show() method must be overridden by subclass.");
		}
		
		public function hide():void {
			//do custom set up in subclass
			throw new ApplicationError("View.hide() method must be overridden by subclass.");
		}
		
		public function reset():void {
			//do custom set up in subclass
			throw new ApplicationError("View.reset() method must be overridden by subclass.");
		}
		
		protected function onHideComplete():void {
			IViewStack(_UIDisplayRoot).viewHideComplete(this);
		}
		
		protected function onShowComplete():void {
			IViewStack(_UIDisplayRoot).viewShowComplete(this);
		}
		
		protected function onAdded():void {
			_log.info("View.onAdded() can be overridden in the subclass to allow for functionality dependend on this object being on the display list.");
		}
	}
}